<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery-1.11.1.min.js"></script>
</head>
<style>
    .box1{
        width: 300px;
        height: 100px;
        border: 1px solid black;
    }
    .box2 {
        width: 300px;
        height: 100px;
        border: 1px solid black;
    }

</style>
<body>
    <div class="box1">
        网站名(key):<input type="text" id="key"><br>
        网址(value):<input type="text" id="value"><br>
        <button id="btn">新增记录</button><br>
    </div>
    <div class="box2">
        输入网站名:<input type="text" id="key1"><br>
        <button id="btn1">查找网址</button>
        <p class="p1"></p>
    </div>
    <table border="1">
        <tr>
            <td>key</td>
            <td>value</td>
        </tr>
    </table>
</body>
<script>
    if(localStorage.length>0){
        for(var i=0;i<localStorage.length;i++){
            $('table').append(`<tr>
            <td>${localStorage.key(i)}</td>
            <td>${localStorage.getItem(localStorage.key(i))}</td>
        </tr>`)
        }
    }else{
        $('table').html('数据为空……')
    }
    var inputKey = document.getElementById('key')
    var inputValue = document.getElementById('value')
    var btn =document.getElementById('btn')
    var btn1 =document.getElementById('btn1')
    var inputKey1 = document.getElementById('key1')
    var p1 =document.getElementsByClassName('p1')[0]
    btn.onclick = function() {
        var key=inputKey.value
        var value= inputValue.value
        localStorage.setItem(key,value)
        location.reload()
    }
    btn1.onclick = function(){
        var key1 = inputKey1.value
        p1.innerHTML=`${key1}的网址是:${localStorage.getItem(key1)}`
    }
</script>
</html>